var mongoose = require('mongoose');

var mongoUri = 'mongodb://localhost:27017/webserver';

mongoose.Promise = global.Promise;

mongoose.connect(mongoUri);

const db = exports.db = mongoose.connection;

db.on('error', err => {
    console.error('和数据库 ' + mongoUri + '的连接出现错误，err: ', err);
});

db.on('open', () => console.log('成功打开数据库 ' + mongoUri));

db.on('connected', err => {
    if (err) return console.error('连接数据库 ' + mongoUri + '失败，err: ', err);
    console.log('成功连接数据库 ' + mongoUri);
});



